package main

import (
	"jinquan.supor.com/common"
	"jinquan.supor.com/samples/mongo/docs"
	"fmt"
	//"reflect"
)


func main() {
	//Pod 内部域名
	/*
	clnt, _ := common.Mongo_ServerConn(`mongodb://mongo-0.mongo.mongo-ns.svc.cluster.local:27017,
											      mongo-1.mongo.mongo-ns.svc.cluster.local:27017,
												  mongo-2.mongo.mongo-ns.svc.cluster.local:27017/?slaveOk=true`, 
												  "secondary")
	*/
	clnt, _ := common.Mongo_ServerConn(`mongodb://mongodb.jinquan.svc.cluster.local:27017`, "primary")
	var userArray  = testdoc.GenDocArray(5)
	var userX = testdoc.GenDocArray(1)
	common.Mongo_CollAddDocs(clnt, "db_3", "coll_1", userArray)
	common.Mongo_CollAddDoc(clnt, "db_4", "coll_1", userX[0])
	
	
	k1 := "Email"
	v1 := common.IfVal_string(userArray[0], k1)
	
	k2 := "Username"
	v2 := common.IfVal_string(userArray[0], k2)

	var docSt = testdoc.GenDocArray(1)
	_,_ = common.Mongo_GetDoc(clnt , "db_3", "coll_1", 
							k1,v1, 
							k2,v2, 
							docSt[0]) 
	
	common.PrintIfFields(docSt[0])
	common.PrintIfType(docSt[0])
	common.PrintIfValue(docSt[0])

	fmt.Printf("%s\t%s\n",
		common.IfVal_string(docSt[0], "Username"),
		common.IfVal_string(docSt[0], "Password") )

	fmt.Printf("%d\t%s\n",
		common.IfVal_integer(docSt[0], "UserId"),
		common.IfVal_string(docSt[0], "Email") )

	fmt.Printf("%s\n",
		common.IfVal_ObjectID(docSt[0], "DocId") )

}